//
// Created by syshen on 2021/4/17.
//

#ifndef EYELIKE_PROJECT_PUPILDETECT_H
#define EYELIKE_PROJECT_PUPILDETECT_H

#include <opencv2/imgproc/imgproc.hpp>

//#include <sys/time.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <math.h>

#include "constants.h"
#include "findEyeCenter.h"
#include "findEyeCorner.h"
#include "retinaface.hpp"


class pupilDetect {
public:
    bool createInstance(std::string mnn_path, std::string landmark_mnn_path, std::string eyesegment_mnn_path, \
                int size, int num_thread, float thresh, float nms);
    pupilDetect(){};
    pupilDetect & operator=(pupilDetect &) =delete;
    pupilDetect(pupilDetect &) = delete;

public:
    std::vector<std::vector<cv::Point>> detect(cv::Mat &img, cv::Mat &left_mask, cv::Mat &right_mask);

    std::vector<std::vector<cv::Point>> detect(cv::Mat &img);

    std::vector<std::vector<cv::Point>> detect(cv::Mat img, cv::Mat &debugImage);

    ~pupilDetect(){
        delete detector;
        delete facelandmark;
        delete eyesegment;
    }

private:

    std::vector<cv::Point> findEyes(cv::Mat &frame_gray, landmark &landm, bool use_dynamic=false);

    std::vector<cv::Point> findEyes(cv::Mat &frame_gray, cv::Rect face);

    std::vector<cv::Point> findEyeCorners(cv::Mat &frame_gray, landmark &landm, cv::Point leftPupil,
                                          cv::Point rightPupil);

    std::vector<cv::Point> findEyeCorners(cv::Mat &frame_gray, cv::Rect &face, cv::Point &leftPupil,
                                          cv::Point &rightPupil);

private:
    Retinaface *detector;
    FaceLandMark *facelandmark;
    EyeSegmentation *eyesegment;
};


#endif //EYELIKE_PROJECT_PUPILDETECT_H
